package com.smyx.case2;

import lombok.extern.slf4j.Slf4j;
import org.apache.zookeeper.KeeperException;

import java.io.IOException;

/**
 * @author SmyxCoding
 **/
@Slf4j
public class ZkDistributedLockTest {
    public static void main(String[] args) throws IOException, InterruptedException, KeeperException {
        for (int i = 0; i < 30; i++) {
            final ZkDistributedLock lock = new ZkDistributedLock();
            int finalI = i;
            new Thread(() -> {
                try {
                    lock.zkLock();
                    log.info(">>>>>>>>>>> 线程{} 启动，获取到锁", finalI);
                    Thread.sleep(2 * 1000);
                    lock.zkUnLock();
                    log.info(">>>>>>>>>>> 线程{} 释放锁", finalI);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }).start();
        }
    }
}
